package com.sumainfor.pc.market.controller.dev;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.dao.dev.HousingConditionMapper;
import com.sumainfor.pc.market.feign.Zfeign.ZpcEpcFeign;
import com.sumainfor.pc.market.service.dev.HousingConditionService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 发展部查询房源
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-05-01 14:29
 **/
@Controller
@RequestMapping("/key/HousingCondition")
public class HousingConditionController {

    @Autowired
    HousingConditionService housingConditionService;

    @Autowired
    HousingConditionMapper housingConditionMapper;

    @Autowired
    ZpcEpcFeign zpcEpcFeign;

    /**
    * <p>
    * 根据房源状态查询房源(分页1)
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/selectHousingCondition")
   public JsonResult selectHousingCondition(@RequestBody Map<String,Object> params, Pager pager){
        System.out.println("传递的参数params:"+params);
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        List<String> HouConList = new ArrayList<>();
        if (params.get("StateFour")!=null&& MapUtils.getInteger(params,"StateFour")==4){
            JsonResult zpcResult = zpcEpcFeign.getRepHouList();
            List<Map<String,Object>> zpcList = (List<Map<String, Object>>) zpcResult.get("result");
            for (Map<String,Object> zpcMap:zpcList) {
                if(zpcMap.get("HouCon") !=null){
                    HouConList.add(MapUtils.getString(zpcMap,"HouCon"));
                }
            }
            if (HouConList.size()>0){
                params.put("idList",HouConList);
            }
        }
        System.out.println("工程部查询的HouConList"+HouConList);
        System.out.println("传入的参数"+params);
        Integer cout=housingConditionMapper.selectHousingConditionCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> selectHousingCondition=housingConditionService.selectHousingCondition(params);
         return pageUtils.getJsonResult(selectHousingCondition, params, cout);
    }


    /**
    * <p>
    * 项目下拉框
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/getCommunityList")
    public JsonResult getCommunityList(@RequestBody Map<String,Object> params){
        return housingConditionService.getCommunityList(params);
    }

    /**
    * <p>
    * 根据房源详表编号查询房源信息
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/selectHousingHouInfoId")
    public JsonResult selectHousingHouInfoId(@RequestBody Map<String,Object> params){
        System.out.println("传递的参数params:"+params);
        JsonResult result = new JsonResult();
        return result.put(housingConditionService.selectHousingHouInfoId(params));
    }

    /**
     * 根据房源详表编号查询房源状态
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/getHouInfoIdState")
    public JsonResult getHouInfoIdState(@RequestBody Map<String,Object> params){
         System.out.println("接受的参数"+params);
         JsonResult result = new JsonResult();
         return result.put(housingConditionService.getHouInfoIdState(params));
     }

}
